bangkeapp.factory('mobService', ['$http', '$q', 'url', "userinfoService", "$ionicLoading",
	function($http, $q, url, userinfoService, $ionicLoading) {
		
		// 是否帮客手机会员
		var ismobmember = function(memberid){
	        var deferred = $q.defer();
	        var promise = deferred.promise;
	        var progress;
	        var data = userinfoService.getNewData();
			data.body.memberid = memberid;
	    		
			$http({    
	            method: "JSONP",    
	            url: url + "/ismobmember/queryMobmember?callback=JSON_CALLBACK",  
	            params: {
					"body": angular.toJson(data)
				}
			}).success(function(response) {
				
				var result = response;
				progress = "正确";
				deferred.notify(progress);
				deferred.resolve(result);
			})
			.error(function(error) {
				deferred.reject(error);
			});
			return promise;
	    }
		
		// 根据会员名称查询会员信息
		var getbymembername = function(membername) {
			var deferred = $q.defer();
	        var promise = deferred.promise;
	        var progress;
	        var result = {};
			var member = {};
			member.membername = membername;
	        var data = userinfoService.getData();
			data.request.body.member = []
			data.request.body.member[0] = member;
	    		
			$http({    
	            method: "JSONP",    
	            url: url + "/member/getbymembername?callback=JSON_CALLBACK",  
	            params: {
					"body": angular.toJson(data)
				}
			}).success(function(response) {
				
				if ("M" == response.Response.Header.ResponseCode) {
					result = response;
					progress = true;
				} else {
					progress = false;
				}
				deferred.notify(progress);
				deferred.resolve(result);
			})
			.error(function(error) {
				deferred.reject(error);
			});
			return promise;
		}
		
		// 注册房产会员的时候查询要扣除的红包积分
		var registermobqueryredpacket = function(memberid){
	        var deferred = $q.defer();
	        var promise = deferred.promise;
	        var progress;
	        var data = userinfoService.getNewData();
			data.body.memberid = memberid;
	    		
			$http({    
	            method: "JSONP",    
	            url: url + "/mobregister/queryredpacket?callback=JSON_CALLBACK",  
	            params: {
					"body": angular.toJson(data)
				}
			}).success(function(response) {
				
				var result = response;
				progress = "正确";
				deferred.notify(progress);
				deferred.resolve(result);
			})
			.error(function(error) {
				deferred.reject(error);
			});
			return promise;
	    }
		
		// 帮客房产激活
		var mobregister = function(memberid, referenceid){
	        var deferred = $q.defer();
	        var promise = deferred.promise;
	        var progress;
	        var data = userinfoService.getNewData();
			data.body.memberid = memberid;
			data.body.referenceid = referenceid;
	    		
			$http({    
	            method: "JSONP",    
	            url: url + "/submitmobregister/saveSubmitApply?callback=JSON_CALLBACK",  
	            params: {
					"body": angular.toJson(data)
				}
			}).success(function(response) {
				
				var result = response;
				progress = "正确";
				deferred.notify(progress);
				deferred.resolve(result);
			})
			.error(function(error) {
				deferred.reject(error);
			});
			return promise;
	    }
		
		// 帮客房产首页初始化
		var querymobindexinit = function(memberid){
	        var deferred = $q.defer();
	        var promise = deferred.promise;
	        var progress;
	        var data = userinfoService.getNewData();
			data.body.memberid = memberid;
	    		
			$http({    
	            method: "JSONP",    
	            url: url + "/mobindexinit/queryMobIndexInit?callback=JSON_CALLBACK", 
	            params: {
					"body": angular.toJson(data)
				}
			}).success(function(response) {
				
				var result = response;
				progress = "正确";
				deferred.notify(progress);
				deferred.resolve(result);
			})
			.error(function(error) {
				deferred.reject(error);
			});
			return promise;
	    }
		
		var querymobfacilitatellist = function(memberid){
	        var deferred = $q.defer();
	        var promise = deferred.promise;
	        var progress;
	        var data = userinfoService.getNewData();
			data.body.memberid = memberid;
	    		
			$http({    
	            method: "JSONP",    
	            url: url + "/mobsubordinate/queryFacilitate?callback=JSON_CALLBACK", 
	            params: {
					"body": angular.toJson(data)
				}
			}).success(function(response) {
				
				var result = response;
				progress = "正确";
				deferred.notify(progress);
				deferred.resolve(result);
			})
			.error(function(error) {
				deferred.reject(error);
			});
			return promise;
	    }
		
		// 查询促成人(申请单初始化)
		var querymobfacilitatebystatus = function(memberid, status){
	        var deferred = $q.defer();
	        var promise = deferred.promise;
	        var progress;
	        var data = userinfoService.getNewData();
			data.body.memberid = memberid;
			data.body.cashstatus = status;
	    		
			$http({    
	            method: "JSONP",    
	            url: url + "/mobsubordinate/queryFacilitate?callback=JSON_CALLBACK",  
	            params: {
					"body": angular.toJson(data)
				}
			}).success(function(response) {
				
				var result = response;
				progress = "正确";
				deferred.notify(progress);
				deferred.resolve(result);
			})
			.error(function(error) {
				deferred.reject(error);
			});
			return promise;
	    }
		
		// 提交新申请单保存
		var savebuymobapply = function(apply){
	        var deferred = $q.defer();
	        var promise = deferred.promise;
	        var progress;
	        var data = userinfoService.getNewData();
			data.body = apply;
	    		
			$http({    
	            method: "JSONP",    
	            url: url + "/buymobapply/saveBuyMobApply?callback=JSON_CALLBACK",  
	            params: {
					"body": angular.toJson(data)
				}
			}).success(function(response) {
				
				var result = response;
				progress = "正确";
				deferred.notify(progress);
				deferred.resolve(result);
			})
			.error(function(error) {
				deferred.reject(error);
			});
			return promise;
	    }
		
		// 申请查询
		var selectlstapplyinfo = function(memberid){
	        var deferred = $q.defer();
	        var promise = deferred.promise;
	        var progress;
	        var data = userinfoService.getNewData();
			data.body.memberid = memberid;
	    		
			$http({    
	            method: "JSONP",    
	            url: url + "/mobapplyinfo/findMobApplyInfo?callback=JSON_CALLBACK", 
	            params: {
					"body": angular.toJson(data)
				}
			}).success(function(response) {
				
				var result = response;
				progress = "正确";
				deferred.notify(progress);
				deferred.resolve(result);
			})
			.error(function(error) {
				deferred.reject(error);
			});
			return promise;
	    }
		
		// 退出
		var savequitmobapply = function(){
	        var deferred = $q.defer();
	        var promise = deferred.promise;
	        var progress;
	        var data = userinfoService.getNewData();
			data.body.memberid = userinfoService.getUser().memberid;
	    		
			$http({    
	            method: "JSONP",    
	            url: url + "/quitmobapply/saveQuitMobApply?callback=JSON_CALLBACK",  
	            params: {
					"body": angular.toJson(data)
				}
			}).success(function(response) {
				
				var result = response;
				progress = "正确";
				deferred.notify(progress);
				deferred.resolve(result);
			})
			.error(function(error) {
				deferred.reject(error);
			});
			return promise;
	    }
		
		var confirmpayment = function(securepwd){
	        var deferred = $q.defer();
	        var promise = deferred.promise;
	        var progress;
	        var data = userinfoService.getNewData();
			data.body.memberid = userinfoService.getUser().memberid;
			data.body.securepwd = securepwd;
	    		
			$http({    
	            method: "JSONP",    
	            url: url + "/securepwdchange/confirmPayment?callback=JSON_CALLBACK", 
	            params: {
					"body": angular.toJson(data)
				}
			}).success(function(response) {
				
				var result = response;
				progress = "正确";
				deferred.notify(progress);
				deferred.resolve(result);
			})
			.error(function(error) {
				deferred.reject(error);
			});
			return promise;
	    }
		
		// 撤销申请
		var cancelapply = function(applykey){
	        var deferred = $q.defer();
	        var promise = deferred.promise;
	        var progress;
	        var data = userinfoService.getNewData();
			data.body.memberid = userinfoService.getUser().memberid;
			data.body.applykey = applykey;
	    		
			$http({    
	            method: "JSONP",    
	            url: url + "/revokemobapply/deleteBuyPhoneApply?callback=JSON_CALLBACK", 
	            params: {
					"body": angular.toJson(data)
				}
			}).success(function(response) {
				
				var result = response;
				progress = "正确";
				deferred.notify(progress);
				deferred.resolve(result);
			})
			.error(function(error) {
				deferred.reject(error);
			});
			return promise;
	    }
		return {
			ismember: ismobmember, // 是否帮客房产会员
			getbymembername : getbymembername, // 查询其他会员, 1:推荐人
			registerqueryredpacket : registermobqueryredpacket, // 注册房产会员的时候查询要扣除的红包积分
			register : mobregister, // 帮客房产激活
			queryindexinit : querymobindexinit, // 帮客房产首页初始化
			queryfacilitatebystatus : querymobfacilitatebystatus, // 查询会员的房产信息及促成人
			savebuyapply : savebuymobapply, // 提交申请
			selectlstapplyinfo : selectlstapplyinfo, // 提现记录
			savequitapply : savequitmobapply, // 退出
			confirmpayment : confirmpayment, //  确认密码
			queryfacilitatellist : querymobfacilitatellist, // 查询我的促成人
			cancelapply : cancelapply // 撤销申请
		}
	}
]);